package com.smarth.zhizulian.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseViewHolder;
import com.smarth.zhizulian.R;
import com.smarth.zhizulian.adapter.MyDiscipleAdapter;
import com.smarth.zhizulian.app.BaseActivity;
import com.smarth.zhizulian.bean.Disciple;
import com.smarth.zhizulian.bean.Page;
import com.smarth.zhizulian.bean.lucky.LuckyFriends;
import com.smarth.zhizulian.http.KumaHttp;
import com.smarth.zhizulian.http.utils.RxCompos;
import com.smarth.zhizulian.utils.GlideUtils;
import com.smarth.zhizulian.utils.MoneyUtils;
import com.smarth.zhizulian.utils.listhelper.RefreshHelper;
import com.smarth.zhizulian.utils.listhelper.impl.adapter.RListDataAdapter;
import com.smarth.zhizulian.utils.listhelper.impl.model.HttpListDataModel;
import com.smarth.zhizulian.utils.listhelper.inter.IDataAdapter;
import com.smarth.zhizulian.utils.listhelper.inter.ResponseSender;
import com.smarth.zhizulian.view.LoadingLayout;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import io.reactivex.Observable;

/**
 * Created by 18865 on 2018/2/5.
 */

public class FriendsActivity extends BaseActivity {
    @BindView(R.id.rc_recyclerview)
    RecyclerView rcRecyclerview;
    @BindView(R.id.rv_refresh)
    SmartRefreshLayout rvRefresh;
    @BindView(R.id.ll_loadinglayout)
    LoadingLayout llLoadinglayout;
    private RefreshHelper<List<LuckyFriends>> refreshHelper;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.global_activity_rc);
        ButterKnife.bind(this);
        setTitlebar("我的好友", true);
        initList();
    }

    private void initList() {
        rcRecyclerview.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.VERTICAL, false));
        refreshHelper = new RefreshHelper<>(mContext, llLoadinglayout, rvRefresh);
        refreshHelper.setDataModel(new HttpListDataModel<List<LuckyFriends>>(mContext) {
            @Override
            public Observable<? extends Page> getObservable(ResponseSender<List<LuckyFriends>> responseSender, int page) {
                return KumaHttp.getService().luckyFriends(page)
                        .compose(RxCompos.<Page<LuckyFriends>>getBELoginCompos());
            }
        });
        refreshHelper.setDataAdapter(new RListDataAdapter<LuckyFriends>(R.layout.item_myapprentice) {
            @Override
            protected void convert(BaseViewHolder helper, LuckyFriends item) {
                GlideUtils.loadAvatar(mContext, item.getAvatar(), (ImageView) helper.getView(R.id.iv_avatar));
                helper.setText(R.id.tv_name, item.getUserName());
                helper.setText(R.id.tv_coin, "捡漏" + item.getLuckyCoin() + "金币");
            }
        });
        refreshHelper.refresh();
    }

    public static void open(Context context) {
        Intent i = new Intent(context, FriendsActivity.class);
        context.startActivity(i);
    }
}
